<?php

namespace App\Library\Service;

use App\Library\Logic\InviteLogic;
use App\Library\Logic\SalesRecordLogic;
use App\Library\Logic\ShopOrderLogic;
use App\Library\Requests\Base\BasePageRequest;
use App\Library\Requests\Invite\InviteOrderPageRequest;
use Illuminate\Http\JsonResponse;

class InviteService extends BaseService
{
    /**
     * @return InviteLogic
     */
    private function logic(): InviteLogic
    {
        if (empty($this->logic)) $this->logic = new InviteLogic;
        return $this->logic;
    }


    public function twoPaging($params)
    {

    }

    /**
     * 邀请信息
     * @param BasePageRequest $request
     * @return JsonResponse
     *
     */
    public function list(BasePageRequest $request): JsonResponse
    {
        $data['pageData'] = $this->logic()->list($request);
        $data['mineUpper'] = $this->logic()->mineUpper();
        $data['inviteRecode'] = SalesRecordLogic::inviteRecode();
        return success($data);
    }

    /**
     * 邀请二级订单列表
     * @param InviteOrderPageRequest $request
     * @return JsonResponse
     *
     */
    public function orderPage(InviteOrderPageRequest $request): JsonResponse
    {
        if(!is_null($request->user_id)) $inviteOrder = SalesRecordLogic::fromUserOrderId($request);
        else $inviteOrder = SalesRecordLogic::toUserOrderId();
        return success(ShopOrderLogic::inviteOrderPage($request, $inviteOrder));
    }
}
